//
//  TTInterfaceModel.m
//  WxIOSReaderForiPhone
//
//  Created by apan on 17/5/4.
//  Copyright © 2017年 anzeinfo. All rights reserved.
//

#import "TTInterfaceModel.h"
#import "GDataXMLNode.h"
#import "GDataXMLDocument+HYSerialize.h"
#import "YYModel.h"


//*********************************Model(接口模型基类)************************************
@implementation TTInterfaceModel

-(TTInterfaceModel*)Paser:(NSString*)xmlOrJson{
    return nil; //交给子类去实例化
}
@end


//*********************************Model(JSON)************************************
/*
 json->json NSDictionary->NSObject
 */
@implementation TTInterfaceModelJson
-(TTInterfaceModel*)Paser:(NSString*)xmlOrJson{
    return [[self class] yy_modelWithJSON:xmlOrJson];
}
//子类重写;
+ (NSDictionary *)modelCustomPropertyMapper{
    return nil;
}
+ (NSDictionary *)modelContainerPropertyGenericClass{
    return nil;
}
@end


//*********************************Model(xml)************************************
/*
 xml->NSDictionary->NSObject
 */
@implementation TTInterfaceModelXml
-(TTInterfaceModel*)Paser:(NSString*)xmlOrJson{
    return [[self class] Paser:xmlOrJson withModalClass:[self class]];
}

/**
 解析子类数据，并获取实例化对象(如果需要解析公共参数，该方法可以根据需要重载)

 @param xml xml string
 @param modalClass 模型类型
 @return return value 具体的模型对象
 */
+(TTInterfaceModel*)Paser:(NSString*)xml
         withModalClass:(Class)modalClass{
    //1.xml解析为NSDictionary
    NSError *error = nil;
    GDataXMLDocument *document = [GDataXMLDocument parserXMLString:xml error:&error arrayTitles:[modalClass getArrayTitles]];
    if (error) {
        NSLog(@"%@", error);
        return nil;
    }
    id contentObject = [document contentObject];
    NSLog(@"contentDict:%@",contentObject);
    
    //2.NSDictionary解析为具体Object
    TTInterfaceModelXml *modal = [modalClass yy_modelWithDictionary:contentObject];
    if(nil == modal){
        modal = [[modalClass alloc]init];  //参数错误时，contentObject不为字典类型，modal返回为空
    }
    document = nil;
    return modal;
}
+(NSArray*)getArrayTitles{
    return nil;
}
+ (NSDictionary *)modelCustomPropertyMapper{
    return nil;
}
+ (NSDictionary *)modelContainerPropertyGenericClass{
    return nil;
}
@end
